unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,Soap.EncdDecd,System.NetEncoding,
  System.ZLib,rtcZLib;

type
  TForm1 = class(TForm)
    Btnv_1: TButton;
    Btnv_2: TButton;
    procedure Btnv_1Click(Sender: TObject);
    procedure Btnv_2Click(Sender: TObject);
  private
  public
  end;

var
  Form1: TForm1;

implementation

uses
  Class_KzDebug;

{$R *.dfm}

procedure TForm1.Btnv_1Click(Sender: TObject);
var
  OD:TOpenDialog;
  intStream:TMemoryStream;
  outStream:TMemoryStream;
  Bytes:array of Byte;
//setlength(byt,iCount);
//sm.Read(byt[0],iCount);
begin
  try
    OD:=TOpenDialog.Create(nil);
    if OD.Execute then
    begin
      try
        intStream:=TMemoryStream.Create;
        intStream.LoadFromFile(OD.FileName);

        intStream.Position:=0;
        SetLength(Bytes,intStream.Size);
        intStream.Read(Bytes[0],intStream.Size);
        KzDebug.FileFmt('%S',[TNetEncoding.Base64.EncodeBytesToString(Bytes)]);

        outStream:=TMemoryStream.Create;
        outStream.Position:=0;
        outStream.SetSize(Length(Bytes));
        outStream.Write(Bytes[0],Length(Bytes));
        outStream.SaveToFile('1.jpg');
      finally
        FreeAndNil(intStream);
        FreeAndNil(outStream);
      end;
    end;
  finally
    FreeAndNil(OD);
  end;
end;

procedure TForm1.Btnv_2Click(Sender: TObject);
var
  sVAL:string;
  bYTS:TArray<Byte>;

  sTrm:TStringStream;
begin
  sVAL:='procedure TForm1.Btnv_2Click(Sender: TObject);';
  //KzDebug.FileFmt('%S',[(sVAL)]);

  bYTS:=System.ZLib.ZCompressStr(sVAL);
  ShowMessageFmt('%d',[Length(bYTS)]);


  sTrm:=TStringStream.Create;
  sTrm.SetSize(Length(bYTS));
  sTrm.Write(bYTS,Length(bYTS));
  ShowMessageFmt('%S',[sTrm.DataString]);
  KzDebug.FileFmt('%S:%S',['E',sTrm.DataString]);
end;

end.
